package com.curtis.playwings.ListView;

import java.util.*;

import com.curtis.playwings.*;
import com.curtis.playwings.ListView.*;
import com.curtis.playwings.R.*;
import android.graphics.Color;
import android.content.ClipData.Item;
import android.content.*;
import android.view.*;
import android.widget.*;


//SHS
//Itmes Adapter getView & change color

public class ItemsAdapter extends ArrayAdapter<Items> {
	 
    private final Context context;
    private final ArrayList<Items> itemsArrayList;

    public ItemsAdapter(Context context, ArrayList<Items> itemsArrayList) {

        super(context, R.layout.row, itemsArrayList);

        this.context = context;
        this.itemsArrayList = itemsArrayList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // 1. Create inflater 
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // 2. Get rowView from inflater
        View rowView = inflater.inflate(R.layout.row, parent, false);

        // 3. Get the two text view from the rowView
        TextView labelView = (TextView) rowView.findViewById(R.id.enticket);
        TextView valueView = (TextView) rowView.findViewById(R.id.korticket);
        TextView updateView = (TextView) rowView.findViewById(R.id.update_time);
        TextView from_cityView = (TextView) rowView.findViewById(R.id.from_city);
        TextView to_cityView = (TextView) rowView.findViewById(R.id.to_city);
        TextView issue_dateView = (TextView) rowView.findViewById(R.id.issue_date);
        TextView optional_infoView = (TextView) rowView.findViewById(R.id.optional_info);
        TextView total_priceView = (TextView) rowView.findViewById(R.id.total_price);
        
        // 4. Set the text for textView 
        labelView.setText(itemsArrayList.get(position).getEnticket());
        valueView.setText(itemsArrayList.get(position).getKorticket());
        updateView.setText(itemsArrayList.get(position).getUpdate_time());
        from_cityView.setText(itemsArrayList.get(position).getFrom_city());
        to_cityView.setText(itemsArrayList.get(position).getTo_city());
        issue_dateView.setText(itemsArrayList.get(position).getIssue_date());
        optional_infoView.setText(itemsArrayList.get(position).getOptional_info());
        total_priceView.setText(itemsArrayList.get(position).getTotal_price());
        
        //4.5 Set the color
        setAirline(rowView, itemsArrayList.get(position).getColor());

        // 5. retrn rowView
        return rowView;
    }
    
    public void setAirline(View rowView, String color) {
    	
    	if(color.equals("blue"))
    	{
    	LinearLayout HeadLayout = (LinearLayout) rowView.findViewById(R.id.tickethead);
        HeadLayout.setBackgroundColor(Color.rgb(103,153,255));
    	}
    	else
    	{
    		
    	}
    	
    }
}